package tezhongbing.socket;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class SocketClient2 {
	public static void main(String[] args) throws UnknownHostException, IOException {
		Scanner scanner = null;
		SocketWraper wraper = null;
		try {
			scanner = new Scanner(System.in);
			wraper = new SocketWraper(new Socket("localhost", 8888));
			System.out.println("已经连接上服务器，现在可以输入消息进行通信了！");
			
			String sendMsg = scanner.nextLine();
			wraper.writeLine(sendMsg);
			String receiveMsg = null;
			while(!"close".equalsIgnoreCase(receiveMsg=wraper.readLine())){
				System.out.println("服务器返回："+receiveMsg);
				sendMsg = scanner.nextLine();
				wraper.writeLine(sendMsg);
			}
			System.out.println("我是客户端，结束了！");
		}finally{
			if(scanner != null){
				scanner.close();
			}
			wraper.close();
		}
	}
}
